import 'package:elephant_fish/model/user.dart';
import 'package:elephant_fish/util/size_util.dart';
import 'package:elephant_fish/widget/black_list_card.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class SettingBlackListPage extends StatefulWidget {
  const SettingBlackListPage({Key key}) : super(key: key);

  @override
  _SettingBlackListPageState createState() => _SettingBlackListPageState();
}

class _SettingBlackListPageState extends State<SettingBlackListPage> {
  List<User> userList = [];
  bool _loading = false;
  ScrollController _scrollController = ScrollController();
  @override
  void initState() {
    super.initState();
    _scrollController.addListener(() {
      var dis = _scrollController.position.maxScrollExtent -
          _scrollController.position.pixels;
      //当距离底部不足300时加载更多
      if (dis < 300 && !_loading) {
        _loadData(loadMore: true);
      }
    });
    _loadData();
  }


  @override
  void dispose() {
    super.dispose();
    _scrollController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xff140c3d),
      appBar: AppBar(
        backgroundColor: Color(0xff140c3d),
        centerTitle: true,
        leading: GestureDetector(
          child: Icon(
            Icons.arrow_back_ios,
            size: SizeUtil.px(32),
            color: Color(0xfff3f3f3),
          ),
          onTap: () {
            Navigator.pop(context);
          },
        ),
        title: Text(
          '黑名单',
          style: TextStyle(fontSize: SizeUtil.px(32), color: Color(0xfff5f5f5)),
        ),
      ),
      body:
      ListView.builder(
          itemCount: userList.length,
          controller: _scrollController,
          shrinkWrap: true,
          itemBuilder:(context,index){
            return BlackListCard(user: userList[index],);
          }
      ),
    );
  }
  _loadData({loadMore = false})async{
    for(int i = 0 ; i < 30;i++){
      User user = User(10000+i, '张三' + i.toString() ,'https://img1.baidu.com/it/u=729283109,1369002854&fm=26&fmt=auto&gp=0.jpg',156,468,'456456465');
      userList.add(user);

    }
  }
}
